class Solution(object):
    def arrangeWords(self, text):
        s = text.split(' ')
        s[0] = s[0].lower()
        s = [[c, index] for index, c in enumerate(s)]
        s.sort(key=lambda x: (len(x[0]), x[1]))
        s = [c[0] for c in s]
        s[0] = s[0][0].upper() + s[0][1:]
        return ' '.join(s)
